home *** CD-ROM | disk | FTP | other *** search
- /*
- WaveTableSynthPlay 12:32:47 PM 10/13/92 • Brigham Stevens
-
- Shows how to use the waveTableSynth
-
- InitDialogs is called only to install crash handler in case
- no Debugger exists.
-
- BuildProgram WaveTableSynthPlay
- */
-
- #include <Dialogs.h>
- #include <Sound.h>
- #include <Memory.h>
-
- #define WAVE_SIZE (512*50)
-
- void WaveTableSynthPlay()
- {
- SndChannelPtr chan;
- SndCommand mycmd;
- unsigned char *wave;
- unsigned char *waveSurfer;
- short soundByte;
- short change = 0;
- short err;
- long tickTime;
-
- /* Nab some memory for a waveTable to build our sound */
- wave = (char *) NewPtr (WAVE_SIZE);
- if(!wave) {
- DebugStr("\pNewPtr failed to make wave...");
- return;
- }
-
- /* create a channel linked with the waveTableSynth */
- chan = nil;
- err = SndNewChannel (&chan, waveTableSynth, initChan0, nil);
- if (err) {
- DebugStr("\p error SndNewChannel [1]");
- goto bail;
- }
-
- /* generate a cool wave */
- waveSurfer = wave;
- for (soundByte = 0; soundByte <= WAVE_SIZE; ++soundByte) {
- *waveSurfer++ = change++;
- if(change > WAVE_SIZE / 4) {
- change += 44;
- }
- }
-
- /* install the wave */
- mycmd.cmd = waveTableCmd;
- mycmd.param1 = WAVE_SIZE;
- mycmd.param2 = wave;
-
- err = SndDoImmediate (chan, &mycmd);
- if (err) {
- DebugStr("\p error SndDoImmediate [1]");
- goto bail;
- }
-
- /* play the wave */
- mycmd.cmd = freqCmd;
- mycmd.param1 = 0;
- mycmd.param2 = 20;
-
- err = SndDoImmediate (chan, &mycmd);
- if (err) {
- DebugStr("\p error SndDoImmediate [2]");
- goto bail;
- }
-
- Delay(180,&tickTime);
-
- /* Now dump the channel */
- err = SndDisposeChannel (chan,false);
- if (err) {
- DebugStr("\p error SndDisposeChannel [1]");
- goto bail;
- }
-
- bail:
- DisposePtr(wave);
- }
-
-
-
- main()
- {
- WaveTableSynthPlay();
- }